<?php
require_once ("../../src/db/connectdatabase.php");
require_once ("../../src/entitys/News.php");

function getNews() {
	$con = new ConnectDB();
	$tbl = "news";
	$fn = array('new_id', 'new_title', 'new_content', 'datecreate');
	$cond = array();
	return $con -> getvalueorderby($tbl, $fn, $cond, 'datecreate');
}

function getNew($idnew) {
	$con = new ConnectDB();
	$tbl = "news";
	$fn = array('new_id', 'new_title', 'new_content', 'datecreate');
	$condetion = array('new_id' => $idnew);
	return $con -> getvalue($tbl, $fn, $condetion);
}

function insertNew($new) {
	$con = new ConnectDB();
	$tbl = "news";
	$fn = array('idtnew' => ($new -> getType()), 'new_title' => ($new -> getTitle()), 'new_tomtat' => ($new -> getTomTat()), 'new_content' => ($new -> getContent()), 'datecreate' => ($new -> getDatecreate()));
	return $con -> insert($tbl, $fn);
}

function updateNew($new) {
	$con = new ConnectDB();
	$tbl = "news";
	$fn = array('idtnew' => ($new -> getType()), 'new_title' => ($new -> getTitle()), 'new_tomtat' => ($new -> getTomTat()), 'new_content' => ($new -> getContent()));
	$condition = array('new_id' => ($new -> getID()));
	return $con -> update($tbl, $fn, $condition);
}

function deleteNew($idnew) {
	$con = new ConnectDB();
	$tbl = "news";
	$condition = array('new_id' => $idnew);
	return $con -> delete($tbl, $condition);
}
?>